/**      
 * 文件名称：OptLogViewAs.as<br>
 * 文件描述：<br>
 * 创建人：马腾<br>
 * 创建时间：Nov 26, 2012 10:36:45 AM<br>
 * 修改人：马腾<br>
 * 修改时间：Nov 26, 2012 10:36:45 AM<br>
 */
import com.mt.system.dto.LogDto;
import com.mt.system.view.OptLogView;
import com.mt.system.domain.Permission;
import com.mt.components.consts.PermissionName;
import com.mt.components.log.LogFactory;
import com.mt.components.log.Logger;
import com.mt.components.utils.RemoteFactory;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.ItemClickEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;

private static var logger:Logger = LogFactory.getLogger(OptLogView);

[Bindable]private var optLogs:ArrayCollection;
private var logDto:LogDto;

public function submit():void {
	logDto = new LogDto();
	logDto.startDate = startDateText.selectedDate;
	logDto.endDate = endDateText.selectedDate;
	logDto.userName = usernameText.text;
	logDto.ip = ipText.text;
	if(logDto.endDate != null && logDto.startDate != null){
		if(logDto.startDate.getTime() > logDto.endDate.getTime()){
			Alert.show("开始日期必须小于结束日期！");
			return;
		}else{
			logDto.endDate.hours = 23;
			logDto.endDate.minutes = 59;
		}
	}
	var remote:RemoteObject = RemoteFactory.getInstance().getRemote("LogService");
	remote.addEventListener(ResultEvent.RESULT , resultCount);
	remote.getOptLogCount(logDto);
}

protected function resultCount(event:ResultEvent):void {
	bar.setTotalRecords(event.result as int);
	var remote:RemoteObject = RemoteFactory.getInstance().getRemote("LogService");
	remote.addEventListener(ResultEvent.RESULT , resultData);
	remote.getOptLogs(logDto , bar.first() , bar.pageSize);
}

protected function resultData(event:ResultEvent):void {
	optLogs = event.result as ArrayCollection;
}

protected function click(event:ItemClickEvent):void {
	var permission:Permission = event.item as Permission;
	logger.debug(permission.toString());
}